<!DOCTYPE html>
<html>

<head>

    {include file="Public/header"}
    <link href="__STATIC__/layout/css/plugins/sweetalert/sweetalert.css" rel="stylesheet">
    <link rel="stylesheet" type="text/css" href="__STATIC__/layout/css/plugins/webuploader/webuploader.css">
    <link rel="stylesheet" type="text/css" href="__STATIC__/layout/css/demo/webuploader-demo.css">
    <style>
        .radio-inline input[type=radio] {
            margin-top: 0px
        }
        .colorRed{color:red;}
        .bqName{padding: 2px 4px;border-radius: 6px;background: #f66;cursor: pointer;}
    </style>

</head>

<body class="white-bg" style="color:#333;padding:3px;">
<div class="white-bg setRemindPeopleK" style="margin:10px">
    <form action="" class="form-inline" id="add" method="post">
        <input type="hidden" name="id" value="{$c_id}">
        <table class="table-bordered table text-center" id="comp_table">
            <tr class="info">
                <td colspan="6" class="text-left">修改竞品</td>
            </tr>
            <tr>
                <td class="text-right">竞品品类</td>
                <td class="text-left">
                    <select name="cate" class="com_cate">
                        <option value="">请选择</option>
                        {volist name="com_cate" id="row"}
                        <option value="{$row.id}" {if $compe.cate==$row.id}selected{/if}>{$row.category_name}</option>
                        {/volist}
                    </select>
                </td>
            </tr>
            <tr>
                <td class="text-right">竞品</td>
                <td class="text-left">
                    <select name="name" class="competitor" id="competitor">
                        <option value="">请选择</option>
                        {volist name="all_compe" id="row"}
                        <option value="{$row.id}" {if $compe.name==$row.id}selected{/if}>{$row.c_name}</option>
                        {/volist}
                    </select>
                </td>
            </tr>
            <tr>
                <td class="text-right">竞品规格<input name="specs" type="hidden" id="guige_hidden" class="form-control" value="{$compe.specs}"></td>
                <td id="guige" class="text-left">
                    {$compe.specs}
                </td>
            </tr>
            <tr>
                <td class="text-right">零售价</td>
                <td class="text-left">
                    <input name="price" type="text" class="form-control" value="{$compe.price}">
                </td>
            </tr>
            <tr>
                <td class="text-right">竞品描述</td>
                <td class="text-left"><textarea name="brief" id="" cols="30" rows="10">{$compe.brief}</textarea></td>
            </tr>
            <tr>
                <td class="text-right">附件</td>
                <td class="text-left">

                </td>
            </tr>
        </table>
        <div class="col-md-12 text-center" style="padding: 10px 0">
            <button class="btn-success btn" id="tijiao">确认并提交</button>
            <button class="btn-warning btn" id="cancelBack">返回</button>
        </div>
        <input type="hidden" name="attach" id="attach">
    </form>
</div>

<!-- 全局js -->
{include file="Public/footer"}
<script>
    $(document).ready(function () {

            //选择竞品分类
            $('body').on('change','.com_cate',function () {
                var id = $(this).val()
                $('#competitor').load('{:url("select/competitor")}?catid='+id)
            })

            //选择竞品
            $('body').on('change','.competitor',function () {
                var _this = this;
                var id = $(this).val()
                $.get('{:url("format")}?id='+id,function (data) {
                    $('#guige').html(data);
                    $('#guige_hidden').val(data);
                })
            })

    })

</script>
<script>
    var cancelBack = document.getElementById('cancelBack')
    cancelBack.onclick = function () {
        var index = parent.layer.getFrameIndex(window.name);
        parent.layer.close(index);
    }

    //提交
    $('#tijiao').on('click',function () {
        var form =  $('#add')
        var serial = form.serialize()
        $.ajax({
            'type':'post',
            'url':form.attr('action'),
            'data':serial,
            'dataType':'json',
            'success':function (data) {
                if(data.success){
                    parent.swal({
                        title: data.msg,
                        type: "success"
                    },function(){
                        parent.layer.close(parent.layer.getFrameIndex(window.name))

                        });
                }else
                    parent.swal({
                        title: data.msg,
                        type: "warning"
                    });
            }
        })
        return false
    })

</script>
</body>

</html>